Remove maintain_selection_offset Flag#5857
Conversation
|
I can't support changes to help with pycrdt, since I don't know much about that. If you want these changes, I suggest explaining the benefits from the POV of Textual. What use case does it solve. Why this is better. You may also want to break it in to several PRs, as this appear to be making multiple changes. |
|
Textual benefits from these changes as they are meant to improve the
These points are somewhat interconnected and - as a side-effect - fixed an "issue" where the cursor won't move if the selection is within the deletion range of an edit (see point 3 under "What I changed" above). From the I thereby see this PR in line with the intended use of Side note: CRDTs and
|
|
Pinging @willmcgugan, @darrenburns and @davidbrochart for re-opening this PR so it does not get lost. |
Please review the following checklist.
Hey 👋
I am combining realtime syncing provided by
pycrdtwith theTextAreawidget and I am pretty impressed by how little code it takes to adapt the widget to my needs, given the complexity ofsrc/textual/document/*.pyandsrc/textual/widgets/_text_area.py.Good job, @darrenburns!
Background Story
The edit flow in the released
TextAreawidget is:with
maintain_selection_offsetdeciding inEdit.dowhether the current selection gets shifted/moved (True) or set as cursor to the end of the edit (False).However, this edit flow is not compatible to CRDTs in
pycrdt.Changes to those CRDTs are announced via callbacks with event objects passed holding the information about a particular change.
For the
Text-CRDT, there is theTextEventevent object holding info about which text range has been deleted and where a particular piece of text has been inserted.This mechanism requires text manipulation on the
TextAreawidget - from the user via keyboard, the API or as update message from remote - to be done with the information given in the callback.It does not provide a way of transporting arbitrary/app-specific metadata, especially not allowing to pass
maintain_selection_offsetflag:I thereby started experimenting whether I could get decent functionality without
maintain_selection_offset.What I Changed
I removed
maintain_selection_offsetfrom the API.Edits via the API (
insert,delete) do not automatically set theTextAreaselection as a cursor to the end of the edit anymore (maintain_selection_offset = Falsebefore), but keep the current selection.See also tests for
ctrl + u(delete to line start)comparison
ctrl + ubefore:


now:
and
ctrl + k(delete to line end).comparison
ctrl + kbefore:


now:
On
clear,maintain_selection_offsethad no effect.Edits deleting a range covering the current
TextAreaselection place the selection as a cursor at the end of the edit.comparison
before:

now:

Selectionnow supports the operatorsin,<,<=,>and>=forLocations (tuples).I updated the tests.
What are your thoughts, especially about the new API behavior?